package fr.alten.grenoble.test.jpatest;

import java.util.List;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;
import javax.persistence.Query;

import fr.alten.grenoble.test.jpatest.model.Personne;
public class App {
	private static final String PERSISTENCE_UNIT_NAME = "todosPU";
	private static EntityManagerFactory factory;

	public static void main(String[] args) {
		factory = Persistence.createEntityManagerFactory(PERSISTENCE_UNIT_NAME);
		EntityManager em = factory.createEntityManager();
		
		Query q = em.createQuery("select p from Personne p");
		List<Personne> personnes = q.getResultList();
		for (Personne personne : personnes) {
			System.out.println(personne);
		}
		System.out.println("Size: " + personnes.size());

		// Create new todo
		em.getTransaction().begin();
		Personne personne = new Personne();
		personne.setNom("DIALLO");
		personne.setPrenom("Zakaria");
		em.persist(personne);
		em.getTransaction().commit();

		em.close();
	}
}
